Bug 46

Bug Description:

This is an inconsistent synchronization bug.
The private field "closed" in org.apache.commons.pool.BaseObjectPool is neither volatile, nor the accesses to "closed" are synchronized.
More details about this bug are at POOL-46 JIRA page.

Interleaving Description:

code snippet 1:
        ...
2 testBasePool.close();
...
code snippet 2:
	...
while (true) {
1 if (testBasePool.isClosed()) {
break;
}
}
...


a)thread 1 checks isClosed at 1 and gets false and keeps looping.
b)thread 2 set "closed" value to true at 2.
c)thread 1 may not see the change of "closed" and still gets false value and keeps looping.

Step c) is not guaranteed to happen. It's effect depends on machine's JVM and CPU.
But thread 1 still runs more loops than expected even if it does stop in the end.

How To Reproduce:

This bug is reproduced under pool 1.2 and JDK 1.6.0_33.
Execute the following scripts to run the test to reproduce the bug (assume the location of the pool test project is pool_test_home).

Linux:
${pool_test_home}/scripts/46.sh
Windows:
%pool_test_home%\scripts\46.bat